package week1;

import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class CustomClassLoad extends ClassLoader {

    public static void main(String[] args) {
        try {
            Class<?> helloClass = new CustomClassLoad().findClass("Hello");
            Method helloMethod = helloClass.getMethod("hello");

            helloMethod.invoke(helloClass.newInstance());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        Path path = Paths.get("E:\\下载\\极客大学\\作业相关\\Hello\\Hello.xlass");
        byte[] fileByte = new byte[0];
        try {
            fileByte = Files.readAllBytes(path);
        } catch (IOException e) {
            e.printStackTrace();
        }
        for (int i = 0; i < fileByte.length; i++) {
            fileByte[i] = (byte) (255 - fileByte[i]);
        }
        return defineClass(name, fileByte, 0, fileByte.length);
    }
}